package org.kymjs.kjframe.utils;

import org.json.JSONObject;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;

public class WebsocketClient {
    private WebSocket webSocket;
    public WebsocketClient(String wsUrl, WebSocketListener listener){
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(wsUrl).build();

        webSocket = client.newWebSocket(request, listener);
    }

    public void stop(){
        webSocket.close(1000,"normal close");
    }

    public void sendMessage(String message) {
        webSocket.send(message);
    }

    public interface WsClientInterface {
        void onOprEvent(String uri);
        void onSdp(JSONObject message);
        void onIceCandidate(JSONObject message);
        void onFeedback(JSONObject message);
        void onBye();
//        void onInviteCode(JSONObject message);
    }
}
